#include "thread_ctrl.hpp"

ThreadCtrl &ThreadCtrl::getInstance()
{
    static ThreadCtrl instance;
    return instance;
}

/**
 * @brief init and start thread and related units
 */
ThreadCtrl::ThreadCtrl()
{
    this->threadInit();
    this->semInit();
    this->mailInit();
    this->queueInit();
    this->threadStart();
}

ThreadCtrl::~ThreadCtrl()
{
}

/**
 * @brief init threads
 */
void ThreadCtrl::threadInit()
{
    this->ledThread = make_unique<LED>(2048, 20, 20, "LedThread");
    this->keyThread = make_unique<KeyPress>(2048, 20, 20, "KeyPress");
    //  this->watchdogThread = make_unique<WatchDog>(2048, 10, 10, "WatchDog");
    // this->EEPROM_24C02Thread = make_unique<EEPROM_24C02>(2048, 21, 20, "24C02");
    this->MCP4728Thread = make_unique<MCP4728>(2048, 15, 20, "MCP4728");
}

/**
 * @brief start threads
 */
void ThreadCtrl::threadStart()
{
    //this->ledThread->start();
    this->keyThread->start();
    //  this->watchdogThread->start();
    // this->EEPROM_24C02Thread->start();
    this->MCP4728Thread->start();
}

/**
 * @brief init semaphores and bind to relative threads
 */
void ThreadCtrl::semInit()
{
}

/**
 * @brief init mailboxes and bind to relative threads
 */
void ThreadCtrl::mailInit()
{
    this->cmdMail = make_shared<Mail<vector<string>, 10>>();
    this->MCP4728Thread->cmdMail = this->cmdMail;
    this->keyThread->cmdMail = this->cmdMail;
}

/**
 * @brief init message Mails and bind to relative threads
 */
void ThreadCtrl::queueInit()
{
}
